<template>
	<view class="count-down" style="position: absolute;" :style="{left,top,width:width+'px',height:height+'px'}">
		<view v-if="percent>0" style="width: 100%;height: 100%;position: relative;">
			<xiaoran-circle v-if="sort == 1" :strokeWidth="10" :percent="percent" :size="width" trailColor="#F1F5E6"
				:stroke-color="'#FBE399'" BgId="BgId1" InId="InId1">
				<view slot="canvas" style="width: 100%;height: 100%;">

					<canvas class="CanvasBox strokeCanvas" canvas-id="BgId1"></canvas>
					<canvas class="CanvasBox trailCanvas" canvas-id="InId1"></canvas>

					<view
						style="position: absolute;left: 50%;top:50%;transform: translate(-50%,-50%);border-radius: 50%;width: 80%;height: 80%;background-color: rgba(255,255,255,0.2);z-index: 1;">
					</view>
				</view>

			</xiaoran-circle>
			<xiaoran-circle v-if="sort == 2" :strokeWidth="10" :percent="percent" :size="width" trailColor="#F1F5E6"
				:stroke-color="'#FBE399'" BgId="BgId2" InId="InId2">
				<view slot="canvas" style="width: 100%;height: 100%;">
			
					<canvas class="CanvasBox strokeCanvas" canvas-id="BgId2"></canvas>
					<canvas class="CanvasBox trailCanvas" canvas-id="InId2"></canvas>
			
					<view
						style="position: absolute;left: 50%;top:50%;transform: translate(-50%,-50%);border-radius: 50%;width: 80%;height: 80%;background-color: rgba(255,255,255,0.2);z-index: 1;">
					</view>
				</view>
			
			</xiaoran-circle>
			<xiaoran-circle v-if="sort == 3" :strokeWidth="10" :percent="percent" :size="width" trailColor="#F1F5E6"
				:stroke-color="'#FBE399'" BgId="BgId3" InId="InId3">
				<view slot="canvas" style="width: 100%;height: 100%;">
			
					<canvas class="CanvasBox strokeCanvas" canvas-id="BgId3"></canvas>
					<canvas class="CanvasBox trailCanvas" canvas-id="InId3"></canvas>
			
					<view
						style="position: absolute;left: 50%;top:50%;transform: translate(-50%,-50%);border-radius: 50%;width: 80%;height: 80%;background-color: rgba(255,255,255,0.2);z-index: 1;">
					</view>
				</view>
			
			</xiaoran-circle>
			<view :style="{'font-size':fonstSize}"
				style="position: absolute;z-index: 4;width: 100%;height: 100%;top:0;color:#FBE399;"
				class="flex flex-x-y flex-y">
				{{time}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "countdown",
		props: {
			fonstSize: {
				type: String,
				default: '60rpx',
			},
			left: {
				type: [String],
				default: '0'
			},
			top: {
				type: [String],
				default: '0'
			},
			width: {
				type: [Number],
				default: 400,
			},
			height: {
				type: [Number],
				default: 400,
			},
			sort: {
				type: [String, Number],
				default: 1,
			}


		},
		mounted() {
			// this.init();
		},
		data() {
			return {
				percent: 0,
				time: 60, //剩余秒数
				show: true,

			};
		},
		methods: {
			init() {
				this.percent = 100;
				this.time = 60;
				this.percent -= (10 / 6);
				this.time--;
				clearInterval(this.timer);
				this.timer = setInterval(() => {
					this.percent -= (10 / 6);
					this.time--;
					if (this.time == 0) {
						clearInterval(this.timer);
					}
				}, 1000);
			}
		}
	}
</script>

<style>
	.count-down {
		width: 300rpx;
		height: 300rpx;
		/* border: 1rpx solid #000; */
	}

	.CanvasBox {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0px;
		left: 0px;

		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 8;
	}
</style>
